package com.example.runlian.pojo;

import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Component;

/**
 *  存储 分页相关信息
 */
@Component
@ConfigurationProperties(prefix = "pojo.pageinfo")
public class PageInfo {
    private Integer page = null;   //第几页
    private Integer size;   //每页查询几条数据
    private Integer totalNumber = null; //总数据条数
    private Integer totalPage = null;   //总页数
    private Integer first = null;      //数据库中起始位置
    private String queryInfo = null ; //查询 信息
    private Integer queryMid = null ; //查询各种 与 mid相关的信息;

    public PageInfo() {
    }


    public Integer getPage() {
        return page;
    }

    public void setPage(Integer page) {
        this.page = page;
    }

    public Integer getSize() {
        return size;
    }

    public void setSize(Integer size) {
        this.size = size;
    }

    public Integer getTotalNumber() {
        return totalNumber;
    }

    public void setTotalNumber(Integer totalNumber) {
        this.totalNumber = totalNumber;
    }

    public Integer getTotalPage() {
        //如果页数大小 和 总的数据条数 都知道了,就求出总页数
        if(totalNumber != null && size != null){
            if(totalNumber%size == 0){
                totalPage = totalNumber/size;
            }else{
                totalPage = totalNumber/size + 1;
            }
        }
        return totalPage;
    }

    public void setTotalPage(Integer totalPage) {
        this.totalPage = totalPage;
    }

    public Integer getFirst() {
        //如果 第几页 和 页面大小 知道了就自动 计算 mysql分页逻辑的 起始数据first
        if(page != null && size != null){
            first = (page - 1) * size;
        }
        return first;
    }

    public void setFirst(Integer first) {
        this.first = first;
    }

    public String getQueryInfo() {
        return queryInfo;
    }

    public void setQueryInfo(String queryInfo) {
        this.queryInfo = queryInfo;
    }

    public Integer getQueryMid() {
        return queryMid;
    }

    public void setQueryMid(Integer queryMid) {
        this.queryMid = queryMid;
    }

    @Override
    public String toString() {
        return "PageInfo{" +
                "page=" + page +
                ", size=" + size +
                ", totalNumber=" + totalNumber +
                ", totalPage=" + totalPage +
                ", first=" + first +
                ", queryInfo='" + queryInfo + '\'' +
                '}';
    }
}
